import { defineSource } from '../source';
import { ProcessedItem } from '../types'
import { myFetch } from "../utils/fetch"
import logger from '../../framework/config/logger';

interface Res {
    data: {
        content: {
            title: string
            content_id: string
        },
        content_counter: {
            hot_rank: string
            comment_count: number
        }
    }[]
}

export default defineSource({
    juejin: async (): Promise<ProcessedItem[]> => {
        const url = `https://api.juejin.cn/content_api/v1/content/article_rank?category_id=1&type=hot&spider=0`
        const res: Res = await myFetch(url)
        return res.data.map((k) => {
            const url = `https://juejin.cn/post/${k.content.content_id}`
            return {
                id: k.content.content_id,
                title: k.content.title,
                url,
                extra: {
                    hot: k.content_counter.hot_rank,
                }
            }
        })
    }
});